package com.llb666.shop.items.domain.entity.bo;

import com.llb666.shop.items.domain.entity.ItemsComments;
import com.llb666.shop.items.domain.entity.ItemsImg;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 登录用户的商品评论.
 *
 * @author llb666
 */
@Data
public class MyCommentBo {
    /**
     * 评论Id.
     */
    private String commentId;

    /**
     * 评论内容.
     */
    private String content;

    /**
     * 发表时间.
     */
    private Date createdTime;

    /**
     * 商品ID.
     */
    private String itemId;

    /**
     * 商品名称.
     */
    private String itemName;
    /**
     * 商品规格.
     */
    private String specName;

    /**
     * 商品图片.
     */
    private String itemImg;


    public static List<MyCommentBo> conver(List<ItemsComments> myComments, List<ItemsImg> itemsImgs) {
        List<MyCommentBo> list = new ArrayList<>();
        Map<String, String> imgMap = itemsImgs.stream().collect(Collectors.toMap(ItemsImg::getItemId, ItemsImg::getUrl));
        for (ItemsComments comment : myComments) {
            MyCommentBo bo = new MyCommentBo();
            bo.setCommentId(comment.getId());
            bo.setContent(comment.getContent());
            bo.setItemId(comment.getItemId());
            bo.setItemName(comment.getItemName());
            bo.setSpecName(comment.getSepcName());
            bo.setCreatedTime(comment.getCreatedTime());
            bo.setItemImg(imgMap.get(comment.getItemId()));
            list.add(bo);
        }
        return list;
    }
}
